home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / baudlck.zip / LOCKOUT.C next >
C/C++ Source or Header  |  1991-12-23  |  9KB  |  165 lines

  1. /*******************************************************************************
  2.  *   FILE LOCKOUT.C                                                            *
  3.  *   Created 01-SEP-1991            Rickie W. Belitz                           *
  4.  *                                  P.O. Box 5895                              *
  5.  *                                  Maryville, Tennessee  37802                *
  6.  *                                  BBS (615) 982-6512 v.32                    *
  7.  *                                      (615) 982-6537 v.32                    *
  8.  *                                      (615) 982-8723 v.32                    *
  9.  *                                                                             *
  10.  *   This code is designed to be used with the CKIT door libraries.            *
  11.  *   The source and program are free.   The source can be modified             *
  12.  *   as desired but no fees should be charged for it or any programs           *
  13.  *   compiled with it.   Some enhancements might be to record the              *
  14.  *   lockouts to a file or the caller log.                                     *
  15.  *   This code was a quick fix for locking out new 1200 baud users             *
  16.  *   on my BBS and allowing me to grandfather my existing 1200 baud            *
  17.  *   users.  PCBoard at the present time does not allow selectively            *
  18.  *   locking out baud rates based on security levels.                          *
  19.  *   Although not perfect, this is the next best thing.  The door is           *
  20.  *   is meant to used as a shelled login door within PCBoard and               *
  21.  *   the door access level set for new user security level.                    *
  22.  *   The door expects the desired baud rate to lock out and the path           *
  23.  *   to pcboard.sys to be passed on the command line.  It will also            *
  24.  *   accept the PORT:AAAA:X cmd to change port and irq if need be.             *
  25.  *   AAAA = port base, and X = irq to use passed as a 3rd argument.            *
  26.  *                                                                             *
  27.  *   An example door bat file might be:                                        *
  28.  *   d:                                                                        *
  29.  *   cd c:\pcb\doors                                                           *
  30.  *   lockout 1200 c:\pcb\pcboard.sys <port:AAAA:X>                             *
  31.  *                                                                             *
  32.  *   Notice there is no "board" statement to return to the BBS since it is     *
  33.  *   a shelled door.                                                           *
  34.  *                                                                             *
  35.  *  Direct any comments/suggestions to the BBS numbers or address above.       *
  36.  *                                                                             *
  37.  *                        Rickie Belitz                                        *
  38.  *******************************************************************************/
  39. #include    <stdio.h>
  40. #include    <malloc.h>
  41. #include    "oldckit.h"          /* For version 2.0 CKit           */
  42. #include    "ckit.h"             /* Include CKIT Header file!      */
  43.  
  44. #define     BELL    0x07
  45.  
  46. /****************************************************************************
  47.  *                   function prototypes                                    *
  48.  ****************************************************************************/
  49. void    print_error(short, char **);    /* Print open_door errors       */
  50. void    send_byte(BYTE);                /* Send single byte out remote  */
  51. void    s_printf(char *, ...);
  52. void        shut_down(void);    /* Shuts door down if normal or error occurs. */
  53.  
  54.  
  55. /****************************************************************************
  56.  *     Misc. variables                                                      *
  57.  ****************************************************************************/
  58. char        progname[21] = "1200 lockout";
  59. short       OPENED;             /* Flag to know if open_door has been called  */
  60. short       CLOSED;             /* Flag to know if close_door has beeb called */
  61. short       LOCKOUT;
  62. void        shut_down(void);    /* Shuts door down if normal or error occurs. */
  63.  
  64. /****************************************************************************
  65.  *     Error messages for open_door()                                       *
  66.  ****************************************************************************/
  67. char    error1[128] = "Error opening system file -> ";
  68. char    error2[128] = "Error reading system file -> ";
  69. char    error3[128] = "Unknown BBS file type     -> ";
  70. char    error4[128] = "Error opening users file  -> ";
  71. char    error5[128] = "Invalid User Record in ->";
  72. char    error6[128] = "Error reading user record -> ";
  73. char    error7[128] = "Port syntax error: USAGE: PORT:AAAA:X AAAA=COMBASE X=IRQ";
  74. char    error8[128] = "Fossil driver not installed";
  75. char    error9[128] = "Unable to allocate memory";
  76. /*****************************************************************************
  77.  *  Create array of pointers to our error messages                           *
  78.  *****************************************************************************/
  79. static  char    *ckit_errors[9] = {
  80.     error1,
  81.     error2,
  82.     error3,
  83.     error4,
  84.     error5,
  85.     error6,
  86.     error7,
  87.     error8,
  88.     error9,
  89.  };
  90.  
  91. /******************************************************************************
  92.  *                     Start of Main Program                                  *
  93.  *****************************************************************************/
  94. main(int argc, char **argv) {
  95. short   result;
  96.  
  97.     CLOSED  = FALSE;            /* Door not closed                       */
  98.     OPENED  = FALSE;            /* Door not opened                       */
  99.     LOCKOUT = FALSE;            /* Wrong baud, dump the user             */
  100.     FORCEOFFHOOK = FALSE;       /* Don't take modem off-hook             */
  101.     if (argc > 1) {
  102.         *(ck_logoff_msgs) = '\0';   /* Don't want to display an exit msg */
  103.         result = open_door(argv[2], argv[3]);
  104.         if(!result) {
  105.             OPENED = TRUE;
  106.             atexit(shut_down);
  107.         } else {
  108.             OPENED = FALSE;
  109.             if(result <= 3) {
  110.                 strcat(ckit_errors[result-1], argv[1]); /* sys file problem */
  111.             } else {
  112.             print_error(result-1, ckit_errors);  /* Port or fossil problem */
  113.             }
  114.             exit(1);
  115.         }
  116.         if(!stricmp(baud_rate, argv[1])) {
  117.             newline();
  118.             s_printf("\aSorry, %s baud is not supported.\r\n", baud_rate);
  119.             newline();
  120.             ck_wait(2);
  121.             LOCKOUT = TRUE;
  122.         }
  123.     } else {
  124.         printf("\nUsage: login.exe baudrate c:\\pcb\\pcboard.sys <port:AAAA:X>\n");
  125.     }
  126.  }
  127. /******************************************************************************
  128. *                       End of Main Program                                   *
  129. ******************************************************************************/
  130. /****************************************************************************
  131.  *      Printf() function for sending output to port                        *
  132.  ****************************************************************************/
  133. void s_printf(char *s_format,...) {
  134.     va_list arg_pointer;
  135.     char buffer[256];
  136.     va_start(arg_pointer, s_format);
  137.     vsprintf(buffer, s_format, arg_pointer);
  138.     s_puts(buffer);
  139.     va_end(arg_pointer);
  140. }
  141.  
  142. /*****************************************************************************
  143.  *  Prints messages, enter with msg table to use                             *
  144.  *****************************************************************************/
  145. void    print_error(short index, char **msg_table) {
  146.     printf(msg_table[index]);
  147. }
  148.  
  149. /****************************************************************************
  150.  *      Close door, reset vectors etc.                                      *
  151.  *  Need in case of a run time error occurs in door                         *
  152.  ****************************************************************************/
  153.  void   shut_down(void) {
  154.     if(OPENED && !CLOSED) {
  155.         close_door();
  156.         CLOSED = TRUE;
  157.         if(LOCKOUT) {     /* Wrong baud, dump the user             */
  158.             lower_dtr();  /* Drop DTR, hang up modem */
  159.         }
  160.     }
  161. }
  162.  
  163. /****************************************************************************/
  164. /************************ E N D  O F   M O D U L E **************************/
  165.